<?php
use yii\helpers\Url;
$this->title = $isComplete ? '会员资料' : '完善会员资料';
?>

<?php if ($isComplete) { ?>
    <!-- <div class="weui_cells_title waringColor">·请填写您的真实信息，有机会获得会员赠礼！</div> -->
<?php } ?>
    <form action="" method="post">
        <div class="weui_cells weui_cells_form titleColor">
            <div class="weui_cell valid-box" id="name_box">
                <div class="weui_cell_hd"><label class="weui_label"></label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <p id="name_valid" class="weui_input valid_input" ></p>
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">昵称</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input id="nickName" class="weui_input " name="last_name" type="text" value="<?= isset($userInfo['last_name']) ? $userInfo['last_name'] : ''  ?>" placeholder="请输入昵称">
                </div>
            </div>

            <div class="weui_cell">
                <div class="weui_cell_hd"><label for="gender"  class="weui_label">性别</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <select class="weui_input" type="text" id='msg_gender' name="gender" required>
                        <option value="男" id="M" name="gender" <?php if($userInfo['gender'] == '男'){echo 'selected';} ?>>男</option>
                        <option value="女" id="F" name="gender" <?php if($userInfo['gender'] == '女'){echo 'selected';} ?>>女</option>
                    </select>
                </div>
            </div>

            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">手机</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input id='iphone' readonly="readonly" class="weui_input" name="mobile" type="text" value="<?= isset($userInfo['mobile']) ? substr($userInfo['mobile'], 2) : '' ?>" style="<?= isset($userInfo['mobile']) ? 'border:none;' : '';?>"  placeholder="请输手机号码">
                </div>
            </div>

            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">生日</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input id="birthday" class="weui_input" name="birthday" type="date" value="<?= isset($userInfo['birthday'])? $userInfo['birthday']: ''?>" placeholder="请选择您的生日" value="1990/01/01">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">电子邮箱</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input id="email" class="weui_input " type="email" name="email" value="<?= isset($userInfo['email'])?$userInfo['email']:""?>" placeholder="输入您常用的电子邮箱">
                </div>
            </div>


        </div>
        <div class="weui_btn_area" id="save">
            <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
            <input name="code" type="hidden" id="code" value="<?= isset($userInfo['code']) ? $userInfo['code'] : '' ?>">
<!--            <input type="button" class="weui_btn weui_btn_primary" href="Usermsg" value="提交">-->
            <input type="button" class="weui_btn weui_btn_primary"  value="提交">
        </div>
    </form>
</div>
<script>
    var save=document.getElementById("save");
    save.onclick=function(){
        formtest();
        console.log(1);
    };
//        $("#save").click(function(){
//
//
//            console.log(1);
//        });

    var formtest=function(){
        var name = document.getElementById("nickName");
        var name_box = document.getElementById("name_box");
        var name_valid = document.getElementById("name_valid");
        var email = document.getElementById("email");

        var reg=/^\s*\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+\s*$/;
        var name_val=name.value.trim();

        var email_val=email.value+"";
        email_val=email_val.trim();
        var reset=function(){
//            name_box.style.cssText="display:none";
            name_valid.innerHTML="";
//            $("#name_box").removeClass("valid_input");
            console.log(2);
        }
        reset();
        if(name_val==""){
//            name_box.style.cssText="display:block";
            name_valid.innerHTML="您的姓名不能为空";
//            $("#name_box").addClass("valid_input");
            name.focus();
            console.log(3);
        }else if(email_val==""){
//            name_box.style.cssText="display:block";
            name_valid.innerHTML="您的邮箱不能为空";
//            $("#name_box").addClass("valid_input");
            email.focus();
            console.log(4);
        }else if(!reg.test(email_val)){
//            name_box.style.cssText="display:block";
            name_valid.innerHTML = "请输入正确格式的邮箱";
//            $("#name_box").addClass("valid_input");
            email.focus();
            console.log(5);
        }
        else{ //通过以上格式验证，才能提交表单；
            $("form").submit();
        }
    }

</script>
